package com.rule.easyrule.config;

import com.rule.easyrule.entity.BizOrder;
import com.rule.easyrule.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.annotation.Rule;

import java.util.Objects;

@Rule(name = "discount_order_rule", description = "折扣订单类型",priority =2)
@Slf4j
public class DiscountOrderRule {

    @Condition
    public boolean when(@Fact("order") BizOrder order) {
        return Objects.equals(order.getType(),2);
    }

    @Action(order = 1)
    public void action(@Fact("order")BizOrder order) {
        log.info("这是一个折扣订单，商品goods:{}",order.getGoods());
    }

    @Action(order = 2)
    public void action2(@Fact("order")BizOrder order) {
        //调用其他业务处理
        OrderService.doDiscountAction(order);
    }
}
